// 各种过滤器
export function bankFormat(bank) {
	// 银行卡格式化  0000 0000 0000 0000 000
	if (!bank) return ''
	var account = new String(bank)
	account = account.substring(0, 25) /*帐号的最大位数 本是23, 包括空格在内 */
	if (account.match('.[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}') == null) {
		/* 对照格式 */
		// 需搞懂此处意思  以防有坑
		if (
			account.match(
				'.[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|' +
					'.[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|' +
					'.[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|' +
					'.[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}|' +
					'.[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{7}'
			) == null
		) {
			let accountNumeric = '',
				accountChar = '',
				i
			for (i = 0; i < account.length; i++) {
				accountChar = account.substr(i, 1)
				if (!isNaN(accountChar) && accountChar != ' ') accountNumeric = accountNumeric + accountChar
			}
			account = ''
			for (i = 0; i < accountNumeric.length; i++) {
				/* 可将以下空格改为-,效果也不错 */
				if (i == 4 || i == 8 || i == 12 || i == 16) account = account + ' ' /* 帐号第n位数后加空格 */
				account = account + accountNumeric.substr(i, 1)
			}
		}
	} else {
		account =
			' ' +
			account.substring(1, 5) +
			' ' +
			account.substring(6, 10) +
			' ' +
			account.substring(14, 18) +
			' ' +
			account.substring(18, 22) +
			' ' +
			account.substring(22, 25)
	}
	return account
}

export function timeFormat(time) {
	// 时间格式化  xx分xx秒
	let m = Math.floor(time / 60)
	let s = time % 60
	m = m < 0 ? '00' : m < 10 ? `0${m}` : m
	s = s < 0 ? '00' : s < 10 ? `0${s}` : s
	return `${m}分${s}秒`
}
